package org.thotheolh.db2json.db.struct;

import java.util.ArrayList;

public class Table {

	private String tableName;
	private ArrayList<Tuple> tupleList = null;

	public Table() {
		tupleList = new ArrayList<Tuple>();
		nextTuple();
	}

	public Table(String tablename) {
		tupleList = new ArrayList<Tuple>();
		nextTuple();
		setTableName(tablename);
	}

	public void setTableName(String tablename) {
		tableName = tablename;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTuples(ArrayList<Tuple> tuples) {
		tupleList = tuples;
	}

	public ArrayList<Tuple> getTuples() {
		return tupleList;
	}

	// Add a raw data
	public void addData(Object data) {
		if (tupleList != null) {
			tupleList.get(tupleList.size() - 1).addRaw(data);
		}
	}

	// Add a key / value pair data set to a tuple.
	public void addData(String key, Object value) {
		if (tupleList != null) {
			tupleList.get(tupleList.size() - 1).addKeyValue(key, value);
		}
	}

	// Creates new tuple in table.
	public void nextTuple() {
		Tuple newTuple = new Tuple();
		tupleList.add(newTuple);
	}
}
